package com.mytest.leetcode;

import lombok.extern.slf4j.Slf4j;

import java.util.*;
import java.util.stream.Collectors;

/**
 * Created by shixi  on 2019/6/24
 */
@Slf4j
public class Solution75 {

    public static void main(String[] args) {
        Solution75 solution = new Solution75();
        int[] nums = {2,1,2};
        solution.sortColors(nums);
        log.info("{}", nums);
    }

    public void sortColors(int[] nums) {
        int R = nums.length -1;
        int L = 0;
        for(int i=0;i< nums.length ;i++){
            while(i <= R && nums[i] == 2){
                int temp = nums[R];
                nums[i] = temp;
                nums[R] = 2;
                R--;
            }
            if(nums[i] == 0) {
                int temp = nums[L];
                nums[i] = temp;
                nums[L] = 0;
                L++;
            }

        }

    }
}

